import { ref} from "vue";
import {  ElMessage }from"element-plus";
import {useStore}from"vuex";
const release = ()=>{
  const imageUrl =ref("")
  const store=useStore();
    const onSubmit = (form) => {
      console.log(form);
      console.log('submit!');
      console.log(imageUrl.value);
      form.goodsImg=imageUrl.value
      store.dispatch("manage/adddataAsync", form);
    }
    const handleAvatarSuccess = (res, file) => {
      imageUrl.value = URL.createObjectURL(file.raw);
    };
    const beforeAvatarUpload = (file) => {
      const isLt2M = file.size / 1024 / 1024 < 2;
      if (!isLt2M) {
        ElMessage.error("上传的图片不得大于 2MB!");
      }
      return isLt2M;
    };
    const error = (err) => {
      alert(err + " \r\n提交失败,请尝试其他图片!");
    };
    return {
        onSubmit,
        imageUrl,
        handleAvatarSuccess,
        beforeAvatarUpload,
        error
    }
}
export{
    release
}
